home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / probots.arc / WIMP.PR < prev   
Text File  |  1991-04-28  |  4KB  |  121 lines

  1.   PROCEDURE Wimp;
  2.  
  3. {   Based on C-Robot "Hunter-Killer"
  4.  
  5.     Original by John Hardin
  6.  
  7.     strategy: Move at medium speed in the direction of the last detected
  8.               robot while scanning 360 degrees quickly. If a robot is
  9.               detected, charge at it at high speed, firing when in range.
  10.               If hit while scanning, run to a random location and resume.
  11.               Don't worry about running into a wall or another robot, since
  12.               that only causes 2% damage.  }
  13.  
  14.     { Wimp "globals" }
  15.   VAR
  16.     d              : Integer; { last damage check }
  17.     dir            : Integer; { direction looking & firing }
  18.     Range          : Integer;
  19.  
  20.  
  21.     PROCEDURE go(dest_x, dest_y : Integer);
  22.       { go to the point specified }
  23.     VAR
  24.       course         : Integer;
  25.     BEGIN
  26.       course := Angle_To(dest_x, dest_y);
  27.       drive(course, 100); { full speed ahead! }
  28.       WHILE (distance(loc_x, loc_y, dest_x, dest_y) > 100) AND (speed > 0)
  29.       DO {nothing} ;
  30.     END;
  31.  
  32.  
  33.     PROCEDURE run;
  34.       { RUN AWAY!! }
  35.     BEGIN 
  36.       go(50+Random(900), 50+Random(900));
  37.     END; { end of run }
  38.  
  39.  
  40.     PROCEDURE Sweep;
  41.       { sweepscan arena for target }
  42.     VAR
  43.       Range          : Integer;
  44.       return         : Boolean;
  45.     BEGIN
  46.       return := False;
  47.       drive(dir, 40); { drive at medium spped towards last target }
  48.       dir := dir DIV 10; { scan only even 10-degree slices }
  49.       dir := dir*10;
  50.       WHILE NOT return DO { scan until we see another robot }
  51.         BEGIN 
  52.           d := damage; { save current level of damage }
  53.           WHILE (damage = d) DO { scan until we take a hit }
  54.             BEGIN 
  55.               dir := dir+10; { increment scan direction }
  56.               dir := dir MOD 360; { MOD 360 }
  57.               Range := scan(dir, 10); { wide-range scan }
  58.               IF (Range > 0) THEN
  59.                 BEGIN
  60.                   return := True; { GOT ONE! }
  61.                   d := -10;
  62.                 END;
  63.             END; { continue scanning }
  64.           IF NOT return THEN run; { Ouch! let's get out of here! }
  65.         END; 
  66.     END; { end of sweep }
  67.  
  68.  
  69.     FUNCTION attack(direc : Integer) : Integer;
  70.       { attack robot at direc }
  71.     VAR
  72.       gotone         : Integer; { got robot flag }
  73.     BEGIN
  74.       gotone := 0; { don't got one }
  75.       dir := direc; { look in direc }
  76.       Range := scan(dir, 3); { narrow resolution }
  77.       WHILE (Range > 0) DO { keep attacking while he's there }
  78.         BEGIN 
  79.           IF (Range > 150) THEN drive(dir, 100) { charge! }
  80.           ELSE drive(dir+180, 100); { we're too close - back up! }
  81.           IF (Range > 40) THEN cannon(dir+3, Range); { fire! }
  82.           Range := scan(dir, 3); { check target again }
  83.           gotone := 1; { flag that we've a target }
  84.         END; 
  85.       IF (gotone = 0) THEN drive(dir, 50); { if we've lost him, trundle along }
  86.       attack := gotone; { towards where we last saw him }
  87.     END; { end of attack }
  88.  
  89.  
  90.     PROCEDURE target;
  91.       { search for and attack target }
  92.     VAR
  93.       startdir       : Integer; { direction robot originally seen at }
  94.       curdir         : Integer; { direction we're currently looking }
  95.     BEGIN
  96.       d := damage; { save current damage }
  97.       startdir := dir; { save original direction }
  98.       curdir := dir-5; { back up 5 degrees }
  99.       WHILE (curdir < startdir+7) AND (d = damage) DO
  100.         { until we've looked through ten degrees }
  101.         IF (attack(curdir) > 0) THEN { is somebody there? }
  102.           BEGIN 
  103.             startdir := dir; { yes - Blast him! }
  104.             curdir := startdir-6; { back up the scanner again so we don't }
  105.           END; { lose him and keep looking }
  106.       curdir := curdir+2; { increment scan direction }
  107.     END; { start scanning again }
  108.  
  109.  
  110.   BEGIN {Wimp main}
  111.     d := damage; { get starting damage }
  112.     dir := 0; { starting scan direction }
  113.     run;
  114.     WHILE True DO { loop is executed forever }
  115.       BEGIN 
  116.         Sweep; { sweep arena at high speed }
  117.         target; { acquire and attack detected robot }
  118.       END; 
  119.   END; { end of Wimp main }
  120.  
  121.